<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class ZpService
{
    /**
	 * 检测评论中的敏感词
	 * @param string $content 评论内容
	 * @param string $type content,title,tag 检测类型
	 * @return array(
	 *   'error_code' => '错误代码'
	 *   'error_msg' => 错误描述
	 * )
	 */
	public function checkWord(&$content,$type)
	{
		$result = array('error_code'=>0,'error_msg'=>'');
		$server = FS("ContentCheck");
		if($server->check($content) > 0)
		{
			$words_found = implode("，", $server->words_found);
			$tt_str = lang('share','word_'.$type);
			$result['error_code'] = $server->result;
			$result['error_msg'] = sprintf(lang('share','word_tips_'. $server->result),$tt_str,$words_found);
		}
		return $result;
	}
        
        
	/**
	 * 根据编号获取评论
	 * @param int $zp_id 评论编号
	 * @return array
	 */
	public function getZpById($zp_id)
	{
		$zp_id = (int)$zp_id;
		if(!$zp_id)
			return false;
		
		static $list = array();
		if(!isset($list[$zp_id]))
		{
			$zpku = FDB::fetchFirst('SELECT * FROM '.FDB::table('zpku').' WHERE zp_id = '.$zp_id);
			if($zpku)
				$zpku['url'] = FU('zp/index',array('sid'=>$zp_id));
			$list[$zp_id] = $zpku;
		}
		return $list[$zp_id];
	}
        
        /**
	 * 保存妆品的评论
	 * @param array $_POST 提交的数据
	 * @return int 评论编号
	 */
	public function saveComment($_POST)
	{
		global $_FANWE;
		$zp_id = intval($_POST['zp_id']);

		$data = array();
                
		$data['cm_content'] = trim($_POST['comment_content']);
         
		$data['cm_userid'] = $_FANWE['uid'];
		
		$data['cm_zpid'] = $zp_id;
		$data['cm_time']=TIME_UTC;
                $data['cm_rate_count']=intval($_POST['pingfen']);
                 
                $data['cm_laiyuan']=trim($_POST['laiyuan']);
                if($data['cm_laiyuan']=='') $data['cm_laiyuan'] = '未知';
		$comment_id = FDB::insert('zp_comments',$data,true);

		

		//分享评论数量加1
		FDB::query('UPDATE '.FDB::table('zpku').' set zp_commentcount = zp_commentcount+1 where zp_id = '.$zp_id);

		
		return $comment_id;
	}
        
        public function getZpComment($comment_id)
	{
		return FDB::fetchFirst('SELECT *
			FROM '.FDB::table("zp_comments").'
			WHERE cmid = '.$comment_id);
	}
}
?>
